package reflection;

//测试Class类的创建方式
public class Test03 {
    public static void main(String[] args) throws ClassNotFoundException {
        Person person = new Student();
        System.out.println("This is " + person.getName());

        //方式1：通过对象获得
        Class c1 = person.getClass();
        System.out.println(c1.hashCode());

        //方式2：通过forname
        Class c2 = Class.forName("reflection.Student");
        System.out.println(c2.hashCode());

        //方式3：通过类名.class
        Class c3 = Student.class;
        System.out.println(c3.hashCode());

        //方式4：包装类有Type属性

        //获得父类类型
        Class c5 = c1.getSuperclass();
        System.out.println(c5);
    }
}

class Person{
    public String name;

    public Person(){

    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                '}';
    }
}

class Student extends Person{
    public Student(){
        this.name = "Student";
    }
}

class Teacher extends Person{
    public Teacher(){
        this.name = "Teacher";
    }
}